package com.kcyu.sfherp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kcyu.sfherp.entity.OrderDetail;
import com.kcyu.sfherp.entity.OrderZd;
import com.kcyu.sfherp.mapper.ms.OrderDetailMapper;
import com.kcyu.sfherp.mapper.ms.OrderZdMapper;
import com.kcyu.sfherp.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/open")
public class OpenController {

    @Autowired
    private OrderZdMapper orderZdMapper;

    @Autowired
    private OrderDetailMapper orderDetailMapper;

    @PostMapping("/getOrderDetail/{id}")
    public ResponseResult getOrderDetail(@PathVariable String id) {
        QueryWrapper<OrderZd> wrapper = new QueryWrapper<>();
        wrapper.eq("dh", id);
        OrderZd orderZd = orderZdMapper.selectOne(wrapper);
        if(orderZd != null) {
            QueryWrapper<OrderDetail> wrapper1 = new QueryWrapper<>();
            wrapper1.eq("dh", id);
            List<OrderDetail> orderDetails = orderDetailMapper.selectList(wrapper1);
            orderZd.setDetail(orderDetails);
        } else {
            return new ResponseResult(300, "无此账单");
        }
        return new ResponseResult(200, orderZd);
    }
}
